package com.atguigu.cf.test;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;

/**
 * author: 封捷
 * date: 2023/1/29 16:41
 * version: 1.0
 */
public class Demo02TaskHasResult {

    public static void main(String[] args) throws ExecutionException, InterruptedException {

        ExecutorService threadPool = ThreadPoolProvider.getThreadPool();

        // 通过 CompletableFuture 封装一个有返回值的任务
        String taskResult = CompletableFuture.supplyAsync(() -> {
            System.out.println("当前线程名称：" + Thread.currentThread().getName());
            return "task result very happy";
        }, threadPool).get();

        System.out.println("taskResult = " + taskResult);

    }

}
